/*
 * @Author: xuwejie 1529315455@qq.com
 * @Date: 2023-10-17 11:40:28
 * @LastEditors: xuwejie 1529315455@qq.com
 * @LastEditTime: 2023-10-30 16:44:03
 * @FilePath: \gaodemap\src\utils\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 * !判断两个高度是否在对应的区间内，并返回boolean类型
 * param1: 需要对比的元素
 * param2: 鼠标当前点击的元素
 * param3: 两者高度之间相差的数值
 * param4: 类型
 */
export const compareTopHeight = (boxDom1, boxDom2, num, key) => {
  let boxDomTop1;
  let boxDomTop2;
  let boxDomHeight1;
  let boxDomHeight2;

  let boxDomLeft1;
  let boxDomLeft2;
  let boxDomWidth1;
  let boxDomWidth2;
  if (key == 1) {
    boxDomTop1 = replaceFun(boxDom1.style.top);
    boxDomTop2 = replaceFun(boxDom2.style.top);
  } else if (key == 2) {
    // 获取元素高度
    boxDomHeight1 = replaceFun(boxDom1.style.height)
    boxDomHeight2 = replaceFun(boxDom2.style.height)
    boxDomTop1 = replaceFun(boxDom1.style.top) + boxDomHeight1 / 2;
    boxDomTop2 = replaceFun(boxDom2.style.top) + boxDomHeight2 / 2;
  } else if (key == 3) {
    // 获取元素高度
    boxDomHeight1 = replaceFun(boxDom1.style.height)
    boxDomHeight2 = replaceFun(boxDom2.style.height)
    boxDomTop1 = replaceFun(boxDom1.style.top) + boxDomHeight1;
    boxDomTop2 = replaceFun(boxDom2.style.top) + boxDomHeight2;
  } else if (key == 4) {
    boxDomLeft1 = replaceFun(boxDom1.style.left)
    boxDomLeft2 = replaceFun(boxDom2.style.left)
  } else if (key == 5) {
    // 获取元素宽度
    boxDomWidth1 = replaceFun(boxDom1.style.width)
    boxDomWidth2 = replaceFun(boxDom2.style.width)
    boxDomLeft1 = replaceFun(boxDom1.style.left) + boxDomWidth1 / 2;
    boxDomLeft2 = replaceFun(boxDom2.style.left) + boxDomWidth2 / 2;
  } else if (key == 6) {
    // 获取元素宽度
    boxDomWidth1 = replaceFun(boxDom1.style.width)
    boxDomWidth2 = replaceFun(boxDom2.style.width)
    boxDomLeft1 = replaceFun(boxDom1.style.left) + boxDomWidth1;
    boxDomLeft2 = replaceFun(boxDom2.style.left) + boxDomWidth2;
  }
  if (key == 1 || key == 2 || key == 3) {
    if (boxDomTop1 - boxDomTop2 <= num && boxDomTop1 - boxDomTop2 >= 0) {
      return true
    } else if (boxDomTop2 - boxDomTop1 <= num && boxDomTop2 - boxDomTop1 >= 0) {
      return true
    } else {
      return false
    }
  } else {
    if (boxDomLeft1 - boxDomLeft2 <= num && boxDomLeft1 - boxDomLeft2 >= 0) {
      return true
    } else if (boxDomLeft2 - boxDomLeft1 <= num && boxDomLeft2 - boxDomLeft1 >= 0) {
      return true
    } else {
      return false
    }
  }
}

export const replaceFun = (event) => {
  if (typeof event == "number") return event;
  if (event) return Number(event.replace(new RegExp("px"), ""))
  else return 0
}